#pragma once
#include <string>
#include "renderstaticmesh.h"
#include "renderEMCubeMap.h"
#include "renderAssistLine.h"
#include "../Utility/GenRandomSeq.h"

enum BRDFType {LAFORTUNE=0, WARD, SV_LAFORTUNE, DIFFUSE, MIRROR};

class CRenderBRDFModels :
	public CRenderStaticMesh
{
public:
	CRenderBRDFModels(void);
	virtual ~CRenderBRDFModels(void);
	virtual HRESULT OnD3D11CreateDevice(ID3D11Device* pd3dDevice, 
		const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, CDirectoryUtil* pDirUtil, void* pUserContext);
	virtual HRESULT OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, 
		IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, CDirectoryUtil* pDirUtil, void* pUserContext );
	virtual void OnD3D11ReleasingSwapChain( void* pUserContext );
	virtual void OnD3D11DestroyDevice( void* pUserContext );
	virtual void InitEffectsVariables();
	virtual void ReloadEffectsDebug(ID3D11Device* pd3dDevice, CDirectoryUtil* pDirUtil);
	virtual void OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, 
		CBaseCamera* pViewCamera, CDirectoryUtil* pDirUtil, double fTime, float fElapsedTime, void* pUserContext );
	virtual void OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
	virtual void AddGUIComp(CDXUTDialog* pControlHud, CDXUTDialog* pControlSampleUI, int iX, int& iY, int iYo, int iWidth, int iHeight);
	void UpdateGUIComponents(CDXUTDialog* pControlDlg);
	virtual void RemoveGUIComp();
	//EM Lighting
	void UpdateLightingEnvironment(CBaseCamera* pViewCamera);
	void ComputeSHIrradEnvMapConstants(ID3DX11Effect* pSHIrradEnvMapEffect, float* pSHCoeffsRed, float* pSHCoeffsGreen, float* pSHCoeffsBlue );
	void InitEMLighting(TCHAR* strEMFileName)
	{
		m_pEMLighting->SetEMFileName(strEMFileName);
	}
public:
	CRenderEMCubeMap* m_pEMLighting;
	std::wstring m_strModelName;
	std::wstring m_strEMLightName;

	//random sample generator
	unsigned int m_iNumRamdomSamples;
	CGenRandomSeq*  m_pRandomNumGen;

	//BRDF parameters
	float m_fCxy;
	float m_fCz;
	float m_fCn;

	float m_fAx;
	float m_fAy;
	//render assist line
	CRenderAssistLine* m_pRenderAssistLine;

	//BRDF rendering
	BRDFType m_curBRDFType;
	CDXUTComboBox* m_ListBRDFTypesCombo;
	CGrowableArray<std::wstring> m_BRDFNamesArray;

	//Effect variables
	ID3DX11EffectTechnique* m_pRenderWardBRDFTech;
	ID3DX11EffectTechnique* m_pRenderLafortuneBRDFTech;
	ID3DX11EffectTechnique* m_pRenderMirrorTech;

	ID3DX11EffectVectorVariable* m_pLafortuneVecs;
	ID3DX11EffectScalarVariable* m_pLafortuneScales;
	ID3DX11EffectVectorVariable* m_pLafortuneLobe;
	ID3DX11EffectVectorVariable* m_pWardVecs;
	ID3DX11EffectScalarVariable* m_pWardScales;

	ID3DX11EffectVectorVariable* m_pEyePt;
	ID3DX11EffectShaderResourceVariable* m_pCubeMapSR;
	ID3DX11EffectScalarVariable* m_pfExpo;
	ID3DX11EffectScalarVariable* m_pfGamma;	
};

